package com.mk.admin.service.impl;

import com.mk.admin.mapper.SurveyMapper;
import com.mk.admin.model.ResultDto;
import com.mk.admin.model.entity.SurveyEntity;
import com.mk.admin.model.vo.SurveyVo;
import com.mk.admin.service.SurveyService;
import com.mk.admin.util.JSONCopy;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class SurveyServiceImpl implements SurveyService {

    @Autowired
    private SurveyMapper surveyMapper;
    @Override
    public ResultDto add(SurveyVo surveyVo) {
        SurveyEntity entity = JSONCopy.copy(surveyVo, SurveyEntity.class);
        return ResultDto.data(surveyMapper.insert(entity));
    }

    @Override
    public ResultDto update(SurveyVo surveyVo) {
        SurveyEntity entity = JSONCopy.copy(surveyVo, SurveyEntity.class);
        return ResultDto.data(surveyMapper.updateById(entity));
    }

    @Override
    public ResultDto delete(int id) {
        return ResultDto.data(surveyMapper.deleteById(id));
    }

    @Override
    public ResultDto status(int id) {
        return ResultDto.data(surveyMapper.status(id));
    }

    @Override
    public ResultDto select(SurveyVo surveyVo) {
        SurveyEntity entity = JSONCopy.copy(surveyVo, SurveyEntity.class);
        return ResultDto.data(surveyMapper.count(entity),surveyMapper.select(entity));
    }
}
